#include "XgW32Processes.h"
#include <psapi.h>
#include <tchar.h>

XgW32Processes::XgW32Processes()
{
	refresh();
}

XgW32Processes::~XgW32Processes()
{
	clear();
}

bool XgW32Processes::refresh()
{
	DWORD aProcesses[1024];
	DWORD cProcesses;
	DWORD cBytes;

	clear();

	if( !EnumProcesses(aProcesses, sizeof(aProcesses), &cBytes) )
	{
		OutputDebugString( _T("XgW32Proccesses::refresh : Error while enumerating processes\n") );
		return false;
	}

	cProcesses = cBytes / sizeof(DWORD);

	UINT i;

	for( i = 0; i < cProcesses; i++ )
	{
		DWORD pid = aProcesses[i];
		_map[ pid ] = pid;
	}

	return true;
}

bool XgW32Processes::clear()
{
	_map.clear();
	return true;
}

XgW32Processes::Iterator XgW32Processes::begin()
{
	return _map.begin();
}

XgW32Processes::Iterator XgW32Processes::end()
{
	return _map.end();
}

XgW32Process XgW32Processes::getProcess(DWORD pid)
{
	return _map[pid];
}